function doSearch() {
	$('#tt').datagrid('load', {
		brushId: $('#brushId').val(),
		name: $('#name').val(),
		isSearchApk: $('#isSearchApk').val()
	});
	$('#tt').datagrid('unselectAll');
}

$(function() {
});

function add() {
	showMyWindow('新增', '/brushConfig/add', 800, 600);
}

function edit() {
	var row = $('#tt').datagrid('getSelected');
	if (row) {
		showMyWindow('编辑', '/brushConfig/' + row.id + '/configUpdate', 800, 600);
	} else {
		showMsg(market.content.title, market.content.tips, alert);
	}
}

function del() {
	var row = $('#tt').datagrid('getSelected');
	$.messager.confirm('温馨提醒', '你确定删除本条数据吗？', function(r) {
		if (r) {
			$.get('/brushConfig/delete?id=' + row.id, function(data) {
				if (data.return_code == '1') {
					top.showMsg(market.content.title, data.return_msg, alert);
					doSearch();
				} else if (data.return_code == '3') {
					top.showMsg(market.content.title, data.return_msg, alert);
				} else {
					$.messager.alert(market.content.title, data.return_msg);
				}
			});
		}
	});
}

function formatterApk(value, row, index) {
	var a = '<a href="#" onclick="editApk(' + "'" + row.id + "','"+ row.baseId + "'" + ')">配置</a> ';
	return a;
}

function formatterCheck(value, row, index) {
	var a = '<a href="#" onclick="brushCheck('+"'"+ row.id +"','" + row.prefix + "','" + row.suffix + "'" + ')">配置</a> ';
	return a;
}

function editApk(id, baseId) {
	showMyWindow('配置', '/brushConfig/' + id + '/apkList?baseId='+baseId, 900, 500)
}

function brushCheck(id,prefix,suffix) {
	if (prefix == 'null') {
		$('#prefix').val('');		
	} else {
		$('#prefix').val(prefix);	
	}
	if (suffix == 'null') {
		$('#suffix').val('');	
	} else {
		$('#suffix').val(suffix);	
	}
	$('#idId').val(id);
	$('#addWin').window('open');
}

function cancel(){
	$('#addWin').window('close');	
}

function save() {
	var id = $('#idId').val();
	var prefix = $('#prefix').val();
	var suffix = $('#suffix').val();
	$.ajax({
		url : '/brushConfig/saveCheck',
		type:'POST',
		datatype:'json',
		data:{'id' : id, 'prefix' : prefix, 'suffix' : suffix},
		success: function(data) {
			if (data.return_code == '1') {
				$("#addWin").window('close');
				$("#tt").datagrid('reload');
				$.messager.alert("提示", "操作成功");
			} else {
				$.messager.alert("提示", "操作失败");
			}
		}
	})
}

